**************************************************
/* Transaction Costs and Congressional Careers: The Effect of Flight Availability on Retirement Decisions */
/* Replication Code */
/* Author: Neil Malhotra */
/* Date Created: February 11, 2020 */
/* Last Updated: April 27, 2021 */
**************************************************

**** Replication Code for Table 1 (main text) and Online Appendix Tables OA2, OA3, OA4, OA5, OA6, OA7 ****

clear
clear matrix
clear mata
set maxvar 32767
set matsize 11000
// Put Your Working Directory Here
import delimited using flights_replication.csv, clear
set more off
 
// Variable Construction for Airports and Flights Variables

// Generate an indicator variable for presence of direct flight for each airport

forvalues i = 1/23 {
gen both_n`i' = dir_origin`i'==1&dir_dest`i'==1
}

// Sum number of airports

egen both_numairports_directflight = rowtotal(both_n*)

// Create District Fixed Effects

gen cycle = . 
recode cycle (.=1) if year==1976|year==1978|year==1980
recode cycle (.=2) if year==1982|year==1984|year==1986|year==1988|year==1990
recode cycle (.=3) if year==1992|year==1994|year==1996|year==1998|year==2000
recode cycle (.=4) if year==2002|year==2004|year==2006|year==2008|year==2010
recode cycle (.=5) if year==2012|year==2014|year==2016

egen district_fe = group (state_number district cycle)

// Account for Deaths and Cabinet Appointments

gen died_office1 = died==congress_start

gen runs_next_appt = runs_next
replace runs_next_appt = . if  state=="MN"&district==7&year==1976&custom_name=="Bob Bergland"
replace runs_next_appt = . if  state=="GA"&district==5&year==1976&custom_name=="Andrew Young"
replace runs_next_appt = . if  state=="MI"&district==4&year==1980&custom_name=="David Stockman"
replace runs_next_appt = . if  state=="WY"&district==1&year==1988&custom_name=="Dick Cheney"
replace runs_next_appt = . if  state=="IL"&district==15&year==1990&custom_name=="Edward Madigan"
replace runs_next_appt = . if  state=="MS"&district==2&year==1992&custom_name=="Mike Espy"
replace runs_next_appt = . if  state=="CA"&district==17&year==1992&custom_name=="Leon Panetta"
replace runs_next_appt = . if  state=="NM"&district==3&year==1996&custom_name=="Bill Richardson"
replace runs_next_appt = . if  state=="CA"&district==32&year==2008&custom_name=="Hilda Solis"

// Add in Missing Observations

recode seniority (.=7) if state=="CA"&district==31&year==1976&custom_name=="Charles Herbert WILSON"
recode seniority (.=8) if state=="CA"&district==31&year==1978&custom_name=="Charles Herbert WILSON"
replace nokken_poole_dim1 = . if state=="HI"&district==2&year==1988&custom_name=="Patsy Mink"


// time series set data

xtset id_unique congress

tsset id_unique congress


// create airport change variables

gen lag_airport = l.both_numairports_directflight

gen change_airport = both_numairports_directflight - l.both_numairports_directflight if both_numairports_directflight!=.&lag_airport!=. 
gen gain_airport = change_airport>0 if both_numairports_directflight!=.&change_airport!=.
gen lost_airport = change_airport<0 if both_numairports_directflight!=.&change_airport!=.


// construct additional controls

gen ideology_folded = abs(nokken_poole_dim1)

// rescale dv for easy readability in table

replace runs_next_appt = runs_next_appt*100

gen runs_next_resc = runs_next*100

// Creat Interaction Term Between Airports Variable and District Area

gen area2 = area/100000

gen area_int = area2*both_numairports_directflight

gen gain_airport_area = area2*gain_airport
gen lost_airport_area = area2*lost_airport
gen change_airport_area = area2*change_airport


// Label Variables for Making Tables

label var both_numairports_directflight "Number of Airports"
label var change_airport "Change in Airports"
label var gain_airport "Gained Airport"
label var lost_airport "Lost Airport"
label var les_score "Legislative Effectiveness Score"
label var nokken_poole_dim1 "Ideology"
label var ideology_folded "Ideology (folded)"
label var seniority "Seniority"
label var anysc "Scandal"
label var area2 "District Area (sq. km / 100,000)"
label var area_int "Number of Airports x District Area"
label var change_airport_area "Change in Airports x District Area"
label var gain_airport_area "Gained Airport x District Area"
label var lost_airport_area "Lost Airport x District Area"
label var majority "In Majority"

// Table 1


areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, absorb(id_unique) robust cluster(district_fe)
outreg2 using table1.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
reg runs_next_appt gain_airport  lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
reg runs_next_appt change_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using table1.tex, dec(2) append label

// Appendix 2 (No Controls)

areg runs_next_appt both_numairports_directflight  c.congress#i.region_number if died_office1==0, absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) replace label
reg runs_next_appt change_airport   c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport   c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  c.congress#i.state_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
reg runs_next_appt change_airport  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport   c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  c.congress if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
reg runs_next_appt change_airport    c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport   c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea2.tex, dec(2) append label

// Appendix 3 (Drop Nearby States)


areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="MD"&state!="VA"&state!="DE"&state!="NJ", robust cluster(district_fe)
outreg2 using tablea3.tex, dec(2) append label

// Appendix 4 (Interaction by Area)

areg runs_next_appt both_numairports_directflight area2 area_int seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) replace label
reg runs_next_appt change_airport area2 change_airport_area seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
reg runs_next_appt gain_airport   lost_airport area2 gain_airport_area lost_airport_area seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight area2 area_int  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
reg runs_next_appt change_airport area2 change_airport_area seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport area2 gain_airport_area lost_airport_area  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight area2 area_int  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
reg runs_next_appt change_airport area2 change_airport_area seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport area2 gain_airport_area lost_airport_area  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea4.tex, dec(2) append label


// Appendix 5 Drop Large Districts


areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&area<100000, absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&area<100000, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&area<100000, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&area<100000, robust cluster(district_fe)
outreg2 using tablea5.tex, dec(2) append label


// Appendix 6 Drop Large States

areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0&state!="AK"&state!="WY"&state!="SD"&state!="MT"&state!="ND", robust cluster(district_fe)
outreg2 using tablea6.tex, dec(2) append label

// Appendix 7: Drop Deaths and Appointments

areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
areg runs_next_resc both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_resc change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_resc gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
areg runs_next_resc both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_resc change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_resc gain_airport lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label





**** Making Table OA8 (40 Mile Radius) ****

clear
clear matrix
clear mata
set maxvar 32767
set matsize 11000
// Put Your Working Directory Here
import delimited using flights_replication_40m, clear
set more off
 
// Generate an indicator variable for presence of direct flight for each airport

forvalues i = 1/20 {
gen both_n`i' = dir_origin`i'==1&dir_dest`i'==1
}

// Sum number of airports

egen both_numairports_directflight = rowtotal(both_n*)

// Create District Fixed Effects

gen cycle = . 
recode cycle (.=1) if year==1976|year==1978|year==1980
recode cycle (.=2) if year==1982|year==1984|year==1986|year==1988|year==1990
recode cycle (.=3) if year==1992|year==1994|year==1996|year==1998|year==2000
recode cycle (.=4) if year==2002|year==2004|year==2006|year==2008|year==2010
recode cycle (.=5) if year==2012|year==2014|year==2016

egen district_fe = group (state_number district cycle)

// Account for Deaths and Cabinet Appointments

gen died_office1 = died==congress_start

gen runs_next_appt = runs_next
replace runs_next_appt = . if  state=="MN"&district==7&year==1976&custom_name=="Bob Bergland"
replace runs_next_appt = . if  state=="GA"&district==5&year==1976&custom_name=="Andrew Young"
replace runs_next_appt = . if  state=="MI"&district==4&year==1980&custom_name=="David Stockman"
replace runs_next_appt = . if  state=="WY"&district==1&year==1988&custom_name=="Dick Cheney"
replace runs_next_appt = . if  state=="IL"&district==15&year==1990&custom_name=="Edward Madigan"
replace runs_next_appt = . if  state=="MS"&district==2&year==1992&custom_name=="Mike Espy"
replace runs_next_appt = . if  state=="CA"&district==17&year==1992&custom_name=="Leon Panetta"
replace runs_next_appt = . if  state=="NM"&district==3&year==1996&custom_name=="Bill Richardson"
replace runs_next_appt = . if  state=="CA"&district==32&year==2008&custom_name=="Hilda Solis"

// Add in Missing Observations

recode seniority (.=7) if state=="CA"&district==31&year==1976&custom_name=="Charles Herbert WILSON"
recode seniority (.=8) if state=="CA"&district==31&year==1978&custom_name=="Charles Herbert WILSON"
replace nokken_poole_dim1 = . if state=="HI"&district==2&year==1988&custom_name=="Patsy Mink"


// time series set data

xtset id_unique congress

tsset id_unique congress


// create airport change variables

gen lag_airport = l.both_numairports_directflight

gen change_airport = both_numairports_directflight - l.both_numairports_directflight if both_numairports_directflight!=.&lag_airport!=. 
gen gain_airport = change_airport>0 if both_numairports_directflight!=.&change_airport!=.
gen lost_airport = change_airport<0 if both_numairports_directflight!=.&change_airport!=.


// construct additional controls

gen ideology_folded = abs(nokken_poole_dim1)

// rescale dv for easy readability in table

replace runs_next_appt = runs_next_appt*100



// Label Variables for Making Tables

label var both_numairports_directflight "Number of Airports"
label var change_airport "Change in Airports"
label var gain_airport "Gained Airport"
label var lost_airport "Lost Airport"
label var les_score "Legislative Effectiveness Score"
label var nokken_poole_dim1 "Ideology"
label var ideology_folded "Ideology (folded)"
label var seniority "Seniority"
label var anysc "Scandal"
label var majority "In Majority"




// Online Appendix OA8


areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
reg runs_next_appt gain_airport   lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
reg runs_next_appt change_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea8.tex, dec(2) append label



**** Making Table OA8 (60 Mile Radius) ****


clear
clear matrix
clear mata
set maxvar 32767
set matsize 11000
// Put Your Working Directory Here
import delimited using flights_replication_60m.csv, clear
set more off
 


// Generate an indicator variable for presence of direct flight for each airport

forvalues i = 1/30 {
gen both_n`i' = dir_origin`i'==1&dir_dest`i'==1
}

// Sum number of airports

egen both_numairports_directflight = rowtotal(both_n*)

// Create District Fixed Effects

gen cycle = . 
recode cycle (.=1) if year==1976|year==1978|year==1980
recode cycle (.=2) if year==1982|year==1984|year==1986|year==1988|year==1990
recode cycle (.=3) if year==1992|year==1994|year==1996|year==1998|year==2000
recode cycle (.=4) if year==2002|year==2004|year==2006|year==2008|year==2010
recode cycle (.=5) if year==2012|year==2014|year==2016

egen district_fe = group (state_number district cycle)

// Account for Deaths and Cabinet Appointments

gen died_office1 = died==congress_start

gen runs_next_appt = runs_next
replace runs_next_appt = . if  state=="MN"&district==7&year==1976&custom_name=="Bob Bergland"
replace runs_next_appt = . if  state=="GA"&district==5&year==1976&custom_name=="Andrew Young"
replace runs_next_appt = . if  state=="MI"&district==4&year==1980&custom_name=="David Stockman"
replace runs_next_appt = . if  state=="WY"&district==1&year==1988&custom_name=="Dick Cheney"
replace runs_next_appt = . if  state=="IL"&district==15&year==1990&custom_name=="Edward Madigan"
replace runs_next_appt = . if  state=="MS"&district==2&year==1992&custom_name=="Mike Espy"
replace runs_next_appt = . if  state=="CA"&district==17&year==1992&custom_name=="Leon Panetta"
replace runs_next_appt = . if  state=="NM"&district==3&year==1996&custom_name=="Bill Richardson"
replace runs_next_appt = . if  state=="CA"&district==32&year==2008&custom_name=="Hilda Solis"

// Add in Missing Observations

recode seniority (.=7) if state=="CA"&district==31&year==1976&custom_name=="Charles Herbert WILSON"
recode seniority (.=8) if state=="CA"&district==31&year==1978&custom_name=="Charles Herbert WILSON"
replace nokken_poole_dim1 = . if state=="HI"&district==2&year==1988&custom_name=="Patsy Mink"


// time series set data

xtset id_unique congress

tsset id_unique congress


// create airport change variables

gen lag_airport = l.both_numairports_directflight

gen change_airport = both_numairports_directflight - l.both_numairports_directflight if both_numairports_directflight!=.&lag_airport!=. 
gen gain_airport = change_airport>0 if both_numairports_directflight!=.&change_airport!=.
gen lost_airport = change_airport<0 if both_numairports_directflight!=.&change_airport!=.


// construct additional controls

gen ideology_folded = abs(nokken_poole_dim1)

// rescale dv for easy readability in table

replace runs_next_appt = runs_next_appt*100



// Label Variables for Making Tables

label var both_numairports_directflight "Number of Airports"
label var change_airport "Change in Airports"
label var gain_airport "Gained Airport"
label var lost_airport "Lost Airport"
label var les_score "Legislative Effectiveness Score"
label var nokken_poole_dim1 "Ideology"
label var ideology_folded "Ideology (folded)"
label var seniority "Seniority"
label var anysc "Scandal"
label var majority "In Majority"



// Online Appendix OA9


areg runs_next_appt both_numairports_directflight seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, absorb(id_unique) robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) replace label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt gain_airport   lost_airport seniority anysc majority les_score ideology_folded  c.congress#i.region_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt change_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress#i.state_number if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
areg runs_next_appt both_numairports_directflight  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, absorb(id_unique)  robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt change_airport seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label
reg runs_next_appt gain_airport lost_airport  seniority anysc majority les_score ideology_folded  c.congress if died_office1==0, robust cluster(district_fe)
outreg2 using tablea7.tex, dec(2) append label





